/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "GameObjectState.h"
#include "MathUtil.h"

namespace PQEngine
{
	GameObjectState::GameObjectState(GameObject *object)
    {
		_gameObject=object;
		assert (_gameObject);
    }

    GameObjectState::~GameObjectState()
    {
    }

	///synchronizes world transform from user to physics
    void GameObjectState::getWorldTransform(btTransform& transform) const
    {
        assert (_gameObject);
		
		btVector3 position=MathUtil::toBullet(_gameObject->getWorldPosition());
		btQuaternion rotation=MathUtil::toBullet(_gameObject->getWorldOrientation());

		transform.setOrigin(position);
		transform.setRotation(rotation);
    }

    void GameObjectState::setWorldTransform(const btTransform& transform)
    {
        assert (_gameObject);
        
		Ogre::Vector3 position=MathUtil::toOgre(transform.getOrigin());
		Ogre::Quaternion orientation=MathUtil::toOgre(transform.getRotation());

        _gameObject->setPosition(position);
        _gameObject->setOrientation(orientation);

		_worldTransform = transform;
    }
}
